import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/// State生命周期tter/material.dart';
import 'package:flutter_app/util/LogUtil.dart';

class CounterWidget extends StatefulWidget {
  final String? text;

  CounterWidget({this.text}) : super();

  @override
  State<StatefulWidget> createState() {
    LogUtil.e("生命周期-----createState--只执行一次");
    return new _CounterWidgetState();
  }
}

class _CounterWidgetState extends State<CounterWidget> {
  @override
  void initState() {
    super.initState();
    //初始化状态
    LogUtil.init();
    LogUtil.e("生命周期-----initState--初始逻辑调用");
  }

  @override
  Widget build(BuildContext context) {
    LogUtil.e("生命周期-----build---构建组件树");
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.text ?? ""),
      ),
      body: Center(
        child: Text("你瞅啥！！"),
      ),
    );
  }

  @override
  void didUpdateWidget(CounterWidget oldWidget) {
    super.didUpdateWidget(oldWidget);
    LogUtil.e("生命周期-----didUpdateWidget--父组件改变并且需要重新绘制 UI");
  }

  @override
  void deactivate() {
    super.deactivate();
    LogUtil.e("生命周期-----deactive---");
  }

  @override
  void dispose() {
    super.dispose();
    LogUtil.e("生命周期-----dispose--回调中释放资源");
  }

  @override
  void reassemble() {
    super.reassemble();
    LogUtil.e("生命周期-----reassemble--热重载时会被调用- Release不调用");
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    LogUtil.e("生命周期-----didChangeDependencies--State发生变化时会被调用");
  }
}
